home *** CD-ROM | disk | FTP | other *** search
/ Sprite 1984 - 1993 / Sprite 1984 - 1993.iso / lib / mkmf / mkmf.library < prev    next >
Encoding:
Text File  |  1991-04-11  |  3.1 KB  |  102 lines

  1. #!/sprite/cmds/csh -f
  2. #
  3. # A script to generate (or regenerate) a library directory  Makefile
  4. # from a prototype Makefile.  If ./Makefile.proto exists, use it, else
  5. # use a common prototype.  This script is invoked for libraries where
  6. # the sources are all in a single directory, except for machine-dependent
  7. # sources, which are in .md subdirectories
  8. #
  9. # We assume we were invoked from mkmf.  Parameters passed in from mkmf
  10. # through environment variables:
  11. #
  12. #    DOMACHINES    names of machines we are supposed to run mkmf on
  13. #    MKMFDIR        directory containing prototype makefiles
  14. #    MKMFFLAGS    arguments to all mkmfs run recursively
  15. #    MACHINES    list of machine names (e.g. "sun2 sun3"), for
  16. #            which there are machine-dependent subdirectories
  17. #            (sun3.md, spur.md, etc.) of this directory.
  18. #    MAKEFILE    name of makefile to create
  19. #    SUBTYPE        additional keyword telling what sort of library
  20. #            this is:  Sprite, X, etc.
  21. #
  22.  
  23. #
  24. # Argument processing.  (Generalized form, even though just one flag so far.)
  25. #
  26. while ($#argv >= 1)
  27.     if ("$1" == '-x') then
  28.     set echo
  29.     endif
  30.     shift
  31. end
  32.  
  33. set subtype=$SUBTYPE
  34. set lib=$cwd:t
  35. set pref='[a-z_A-Z]'
  36. set machines=($MACHINES)
  37. set domachines = ($DOMACHINES)
  38. set makefile=$MAKEFILE
  39. set distdir=($DISTDIR)
  40.  
  41. if (-e $makefile.proto) then
  42.     set proto=$makefile.proto
  43. else
  44.     set proto="${MKMFDIR}/Makefile.library"
  45. endif
  46.  
  47. echo "Generating a Makefile for library $lib using $proto"
  48.  
  49. set nonomatch
  50. set hdrs =( ${lib}*.h )
  51. if ("$hdrs" == "${lib}*.h") set hdrs=()
  52. set pubHdrs=(`echo $hdrs | sed -e "s/[^ ]*Int.h//g"`)
  53. set allSrcs =( ${pref}*.[cylsp] )
  54. #
  55. # Check to see if there were any sources.  The first check (size == 1)
  56. # is only necessary because the second check will cause an error if
  57. # allSrcs contains more than 1024 bytes.
  58. #
  59. if ($#allSrcs == 1) then
  60.     if ("$allSrcs" == "${pref}*.[cylsp]") set allSrcs=()
  61. endif
  62. set mdsrcs =( *.md/${pref}*.[cylsp] )
  63. if ($#mdsrcs == 1) then
  64.     if ("$mdsrcs" == "*.md/${pref}*.[cylsp]") set mdsrcs=()
  65. endif
  66. set allSrcs=($allSrcs $mdsrcs)
  67. set lints = ( *.lint )
  68. if ("$lints" == "*.lint") set lints=()
  69. set manPages = (*.man)
  70. if ("$manPages" == "*.man") set manPages=()
  71.  
  72. #
  73. # Use sed to substitute various interesting things into the prototype
  74. # makefile. The code below is a bit tricky because some of the variables
  75. # being substituted in can be very long:  if the substitution is passed
  76. # to sed with "-e", the entire variable must fit in a single shell argument,
  77. # with a limit of 1024 characters.  By generating a separate script file
  78. # for the very long variables, the variables get passed through (to the
  79. # script file) as many arguments, which gets around the length problem.
  80. #
  81.  
  82. rm -f mkmf.tmp.sed
  83. echo s,"@(ALLSRCS)",$allSrcs,g > mkmf.tmp.sed
  84. echo s,"@(MANPAGES)",$manPages,g > mkmf.tmp.sed2
  85. cat $proto | sed -f mkmf.tmp.sed -f mkmf.tmp.sed2 \
  86.     -e "s,@(DATE),`date`,g" \
  87.     -e "s,@(LINTSRCS),$lints,g" \
  88.     -e "s,@(MACHINES),$machines,g" \
  89.     -e "s,@(NAME),$lib,g" \
  90.     -e "s,@(MAKEFILE),$makefile,g" \
  91.     -e "s,@(PUBHDRS),$pubHdrs,g" \
  92.     -e "s,@(TEMPLATE),$proto,g" \
  93.     -e "s,@(TYPE),$subtype,g" \
  94.     -e "s,@(DISTDIR),$distdir,g" \
  95.     > $makefile
  96. rm -f mkmf.tmp.sed mkmf.tmp.sed2
  97.  
  98. setenv PARENTDIR $cwd
  99. foreach i ($domachines)
  100.     (cd $i.md; mkmf $MKMFFLAGS -f md.mk)
  101. end
  102.